#!/bin/bash

root=$(pwd)
sourse_config_path="./source_config"
branch_name=$1
if [[ -z $branch_name ]]; then
	#statements
	read -p "Input the branch name you want to delete:" branch_name
	echo "branch name you inputted is :$branch_name"
fi

read -p "do you want to delete the branch $branch_name ? [y/n]" should_delete
if [ $should_delete != "yes" -a $should_delete != "y" ]
	then
		exit
fi

echo -e "\033[34mdeleting branch $branch_name repo: `pwd` ...\033[0m"
git branch --delete $branch_name
git push origin --delete $branch_name

cat $sourse_config_path | while read source_config || [[ -n "$source_config" ]]; do
	if [[ -n $source_config ]]; then
		repo_name=$(echo $source_config | awk '{print $1}' )
		echo "repo_name :$repo_name" 

		if [[ -d $repo_name ]]; then
			echo -e "\033[34mdeleting branch $branch_name repo: $repo_name ...\033[0m"
			cd $repo_name
			git branch --delete $branch_name
			git push origin --delete $branch_name
			cd $root
		fi
	fi
done
